import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import api from './api/api'
import moment from "moment";
Vue.prototype.$api = api

Vue.use(ElementUI);
Vue.config.productionTip = false
import global from "@/components/global";
Vue.prototype.GLOBAL = global;
Vue.filter('searchRed', function (value,search) {
  if (value && value.length > 0) {
    const reg = `/${search}/g`;
    value = value.replace(
        eval(reg),
        "<span style='color: red;'>" + search + "</span>"
    );
    return value
  }
  //return null
})
Vue.filter('ellipsisLength', function (value,length) {
  if (!value) return "";
  if (value.length > length) {
    return value.slice(0, length) + "...";
  }
  return value;
})
Vue.filter('clearEditor', function (value) {
  if (!value) return ''
  value = value.toString().replace(/<[^>]+>|&[^>]+;/g, "")
  return value
})

Vue.filter('timeFormatedd', function (value) {
  return moment(value).format('DD')
})
Vue.filter('timeFormateyyyymm', function (value) {
  return moment(value).format('YYYY.MM')
})
Vue.filter('timeFormatemmdd', function (value) {
  return moment(value).format('MM-DD')
})
Vue.filter('timeFormateyyyymmdd', function (value) {
  return moment(value).format('YYYY-MM-DD')
})
Vue.filter('timeFormateYYYYMMDD', function (value) {
  return moment(value).format('YYYY-MM-DD HH:mm:ss')
})

window.$confirm = (tex)=>{
  return new Promise((resolve,reject)=>{
    Vue.prototype.$confirm(tex,'提示',{
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning'
    }).then(() => {
      resolve()
    }).catch(() => {
      reject()
    });
  })
}
// api.getLoginStatus().then(res=>{
//     console.log(res)
//     console.log(router)
// })

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')

